package com.scl.springtalis.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.autoconfigure.PageHelperProperties;
import com.scl.springtalis.mapper.EmpMapper;
import com.scl.springtalis.polo.Emp;
import com.scl.springtalis.polo.PageBean;
import com.scl.springtalis.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;


    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);
        List<Emp> list = empMapper.list(name, gender, begin, end);
        Page<Emp> P=(Page<Emp>) list;
        PageBean pageBean = new PageBean(P.getTotal(),P.getResult());
        return pageBean;
    }

    @Override
    public void delect(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void save(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id) {
        Emp byId = empMapper.getById(id);
        return byId;
    }

    @Override
    public Emp update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
        return null;
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.login(emp);
    }
}
